﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.orders {
    import Classes.*;

    public class TrainOrder extends AbstractOrder {

        public static const WELCOME_TRAIN_ID:String = "-2";
        public static const AMBIENT_TRAIN_ID:String = "-3";
        public static const BUY:String = "buy";
        public static const SELL:String = "sell";
        public static const NON_STOP:String = "nonStop";
        public static const ORDER_ACTION:String = "orderAction";
        public static const COMMODITY_TYPE:String = "orderCommodity";
        public static const AMOUNT_PROPOSED:String = "amountProposed";
        public static const AMOUNT_FINAL:String = "amountFinal";
        public static const TRAIN_ITEM_NAME:String = "trainItemName";
        public static const DEFAULT_PRICE:Number = 50;

        protected var m_autoComplete:Boolean = false;
        protected var m_isFakeOrder:Boolean = false;
        protected var m_customPickUrl:String;

        public function TrainOrder(_arg1:String, _arg2:String, _arg3:String=null, _arg4:String=null, _arg5:uint=0, _arg6:String="", _arg7:String=null, _arg8:String=null){
            super(_arg1, _arg2, OrderType.TRAIN, _arg7);
            this.setAction(_arg3);
            this.setCommodityType(_arg4);
            this.setAmountProposed(_arg5);
            setState(OrderStates.PENDING);
            this.setTrainItemName(_arg6);
            this.m_customPickUrl = _arg8;
        }
        public static function getCostPerCommodity(_arg1:String, _arg2:String, _arg3:String):Number{
            var _local4:Item = Global.gameSettings.getItemByName(_arg2);
            var _local5:XML = Global.gameSettings.getCommodityXMLByName(_arg1);
            var _local6:Number = DEFAULT_PRICE;
            if (_local4){
                switch (_arg3){
                    case BUY:
                        _local6 = _local4.trainBuyPrice;
                        break;
                    case SELL:
                        _local6 = _local4.trainSellPrice;
                        break;
                };
            } else {
                if (_local5){
                    _local6 = _local5.@price;
                };
            };
            return (_local6);
        }
        public static function getCostPerCommodityFakeBuy():int{
            return (Global.gameSettings.getInt("trainOrderFakeBuyCostPerCommodity", 60));
        }
        public static function getCostPerCommodityFakeSell():int{
            return (Global.gameSettings.getInt("trainOrderFakeSellCostPerCommodity", 40));
        }

        public function set autoComplete(_arg1:Boolean):void{
            this.m_autoComplete = _arg1;
        }
        public function get autoComplete():Boolean{
            return (this.m_autoComplete);
        }
        public function set fakeTrainOrder(_arg1:Boolean):void{
            this.m_isFakeOrder = _arg1;
        }
        public function get fakeTrainOrder():Boolean{
            return (this.m_isFakeOrder);
        }
        public function get customPickUrl():String{
            return (this.m_customPickUrl);
        }
        public function get baseOrder():Boolean{
            return ((this.getRecipientID() == Player.FAKE_USER_ID_STRING));
        }
        public function getCoinCostProposed():uint{
            return (Math.floor((m_params[AMOUNT_PROPOSED] * getCostPerCommodity(m_params[COMMODITY_TYPE], this.getTrainItemName(), this.getAction()))));
        }
        public function getCoinCostFinal():uint{
            return (Math.floor((m_params[AMOUNT_FINAL] * getCostPerCommodity(m_params[COMMODITY_TYPE], this.getTrainItemName(), this.getAction()))));
        }
        public function getAction():String{
            return (m_params[ORDER_ACTION]);
        }
        public function getCommodityType():String{
            return (m_params[COMMODITY_TYPE]);
        }
        public function getAmountProposed():uint{
            return (m_params[AMOUNT_PROPOSED]);
        }
        public function setAmountProposed(_arg1:uint):void{
            m_params[AMOUNT_PROPOSED] = _arg1;
        }
        public function setAction(_arg1:String):void{
            m_params[ORDER_ACTION] = _arg1;
        }
        public function setCommodityType(_arg1:String):void{
            m_params[COMMODITY_TYPE] = _arg1;
        }
        public function getAmountFinal():uint{
            return (m_params[AMOUNT_FINAL]);
        }
        public function setAmountFinal(_arg1:uint):void{
            m_params[AMOUNT_FINAL] = _arg1;
        }
        public function setTrainItemName(_arg1:String):void{
            m_params[TRAIN_ITEM_NAME] = _arg1;
        }
        public function getTrainItemName():String{
            return (m_params[TRAIN_ITEM_NAME]);
        }
        public function hasExpired():Boolean{
            var _local2:uint;
            var _local3:uint;
            if (this.m_isFakeOrder){
                return (true);
            };
            var _local1:Item = Global.gameSettings.getItemByName(this.getTrainItemName());
            if (_local1){
                _local2 = uint((GlobalEngine.getTimer() / 1000));
                _local3 = _local1.trainTripTime;
                return (((_local2 - getTimeSent()) >= _local3));
            };
            return (true);
        }
        override public function getParams():Object{
            var _local1:Object = new Object();
            _local1[SENDER_ID] = m_params[SENDER_ID];
            _local1[RECIPIENT_ID] = m_params[RECIPIENT_ID];
            _local1[TIME_SENT] = m_params[TIME_SENT];
            _local1[AMOUNT_PROPOSED] = m_params[AMOUNT_PROPOSED];
            _local1[AMOUNT_FINAL] = m_params[AMOUNT_FINAL];
            _local1[COMMODITY_TYPE] = m_params[COMMODITY_TYPE];
            _local1[ORDER_ACTION] = m_params[ORDER_ACTION];
            _local1[ORDER_TYPE] = m_params[ORDER_TYPE];
            _local1[TRAIN_ITEM_NAME] = m_params[TRAIN_ITEM_NAME];
            return (_local1);
        }
        override public function equals(_arg1:AbstractOrder):Boolean{
            var _local2:TrainOrder;
            if ((_arg1 is TrainOrder)){
                _local2 = (_arg1 as TrainOrder);
                return (((super.equals(_arg1)) && ((this.fakeTrainOrder == _local2.fakeTrainOrder))));
            };
            return (false);
        }

    }
}//package Classes.orders 
